package com.example.xadmin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.xadmin.common.Pageable;
import com.example.xadmin.common.Result;
import com.example.xadmin.pojo.SysRole;
import com.example.xadmin.pojo.SysUser;
import com.example.xadmin.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2020-04-05
 */
@Controller
@RequestMapping("/sys-role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @ResponseBody
    @RequestMapping("/list")
    public Result all(Pageable pageable){

        Page res = sysRoleService.page(pageable.toPage());

        return Result.ok((int)res.getTotal(),res.getRecords());
    }


    @GetMapping("/add-html")
    public String add(Model model) throws Exception {
        model.addAttribute("sysRole",new SysRole());
        return "role/role-add";
    }


    @ResponseBody
    @PostMapping("/add")
    public Object add(SysRole sysRole){
        sysRoleService.save(sysRole);
        return Result.ok(1,null);
    }


}

